import { Message, Modal, ModalConfig, Space } from '@arco-design/web-vue';
import { IconExclamationCircleFill } from '@arco-design/web-vue/es/icon';

const success = (msg?: string) => {
  if (!msg) {
    msg = '操作成功';
  }
  Message.success({ content: msg, id: 'success' });
};

const warning = (msg: string) => {
  Message.warning({ content: msg, id: 'warning' });
};

const fail = (msg?: string) => {
  if (!msg) {
    msg = '操作失败';
  }
  Message.error({ content: msg, id: 'fail' });
};

const confirm = (
  content: string,
  ok: () => any,
  config?: Partial<ModalConfig>
) => {
  Modal.confirm({
    ...config,
    title: '提示',
    content: () =>
      h(Space, null, {
        default: () => [
          h(IconExclamationCircleFill, {
            size: 24,
            style: 'color: rgb(var(--orange-6))',
          }),
          h('span', {
            style: 'font-size: 16px;white-space: pre-line;',
            innerHTML: content,
          }),
        ],
      }),
    width: config?.width || 'auto',
    titleAlign: 'start',
    simple: false,
    modalClass: 'm-confirm',
    maskClosable: false,
    escToClose: false,
    onOk: () => {
      ok();
    },
  });
};

const MessageInfo = {
  success,
  fail,
  confirm,
  warning,
  error: fail,
};
export default {};
export { MessageInfo };
